import router from "@/router"

const getRoutes = (list: Menu[]) => {
    let menus = new Array<Menu>();
    list.forEach(v => {
        if (v.children) {
            menus.push(...getRoutes(v.children), v);
        } else {
            menus.push(v)
        }
    })
    return menus
};


const removeRoutes = (list: Menu[]) => {
    let names = getRoutes(list).map(v => {
        return v.name
    })
    console.log("rouers1", router.getRoutes())
    router.getRoutes().forEach(v => {
        if (v.name === undefined || v.meta.isDefault === true) { return } else {
            if (!names.includes(v.name as string)) {
                router.removeRoute(v.name)
                console.log("remove", v.name, router.hasRoute(v.name))
                
            
            }
        }
    })

    console.log("rouers2", router.getRoutes())
};

export { getRoutes, removeRoutes }